// Notification.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "aygshell.h"
#include "resource.h"
HINSTANCE g_hInst;
// {A46E7FCD-7CDC-4dbf-9B39-91551C94A731}
static const GUID CLSID_SHNAPI_Test = 
{ 0xa46e7fcd, 0x7cdc, 0x4dbf, { 0x9b, 0x39, 0x91, 0x55, 0x1c, 0x94, 0xa7, 0x31 } };

int _tmain(int argc, _TCHAR* argv[])
{
	//Parameters to app: 1. HTML Text to display(old Data+new data), 2. Only New data 
	SHNOTIFICATIONDATA sn  = {0};
	sn.cbStruct = sizeof(sn);
	// This code will add an SHNotification notificaion (PocketPC only)
	if(argc > 2)
	{
		SHNotificationGetData(&CLSID_SHNAPI_Test, 1, &sn);//Check if notification is already active
		if(sn.dwID == 1)
		{
			//Notification Active: Update it
			sn.pszHTML = argv[2];
			SHNotificationUpdate(SHNUM_HTML, &sn);
		}	
		else
		{
			HKEY   hkey;
			DWORD  dwDisposition;
 			DWORD dwType, dwSize;

			if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\SmsRule\\SmsFiltered"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==ERROR_SUCCESS)
			{
				dwType = REG_SZ;
				CHAR m_szZero[1];
				strcpy(m_szZero,"0");
				RegSetValueEx(hkey, TEXT("Moved"), 0, dwType, (const unsigned char*)m_szZero,sizeof(m_szZero));
				RegSetValueEx(hkey, TEXT("Copied"), 0, dwType, (const unsigned char*)m_szZero,sizeof(m_szZero));
				RegSetValueEx(hkey, TEXT("Hid"), 0, dwType, (const unsigned char*)m_szZero,sizeof(m_szZero));
 
				RegCloseKey(hkey);
			}
			//Clean Registry
			//No Notification use new text and create new notification
			g_hInst = GetModuleHandle(NULL);
			sn.dwID = 1;
			sn.npPriority = SHNP_INFORM;
			sn.csDuration = 10;
			sn.hicon = LoadIcon(g_hInst,MAKEINTRESOURCE(102));
			sn.clsid = CLSID_SHNAPI_Test;
			sn.grfFlags = SHNF_SILENT ;/*SHNF_DISPLAYON SHNF_SILENT*/
			sn.pszTitle = TEXT("SMS Rule");
			sn.pszHTML = argv[1];
			sn.rgskn[0].pszTitle = TEXT("Dismiss");
			sn.rgskn[0].skc.grfFlags = NOTIF_SOFTKEY_FLAGS_DISMISS;
			sn.rgskn[0].skc.wpCmd = 1000;
			SHNotificationAdd(&sn);
		}
		//sn.pszTodayExec = NULL;
		//sn.rgskn[1].skc.grfFlags = NOTIF_SOFTKEY_FLAGS_HIDE;
		//sn.rgskn[1].pszTitle = TEXT("Minimise");
		//sn.rgskn[1].skc.wpCmd = 1001;
		//Add the notification to the tray
		//SHNotificationAdd(&sn);
		//Remove the notification from the tray
		//SHNotificationRemove(&CLSID_SHNAPI_Test, 1);
	}
	return 0;
}
